<template>
  <div class="playlist-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <img :src="playlist.coverImgUrl" alt="" />
      </div>
      <div class="info-wrap">
        <p class="title">{{playlist.name}}</p>
        <div class="author-wrap">
          <img class="avatar" :src="playlist.creator.avatarUrl" alt="" />
          <span class="name">{{playlist.creator.nickname}}</span>
          <span class="time">{{playlist.createTime}}</span>
        </div>
        <div class="play-wrap">
          <span class="iconfont icon-circle-play"></span>
          <span class="text">播放全部</span>
        </div>
        <div class="tag-wrap">
          <span class="title">标签:</span>
          <ul>
            <li v-for="(tag, index) in playlist.tags" :key="index">{{tag}}</li>
          </ul>
        </div>
        <div class="desc-wrap">
          <span class="title">简介:</span>
          <span class="desc"
            >{{playlist.description}}</span
          >
        </div>
      </div>
    </div>
    <el-tabs v-model="activeIndex">
      <el-tab-pane label="歌曲列表" name="1">
        <table class="el-table playlit-table">
          <thead>
            <th></th>
            <th></th>
            <th>音乐标题</th>
            <th>歌手</th>
            <th>专辑</th>
            <th>时长</th>
          </thead>
          <tbody>
            <tr class="el-table__row" v-for="(track, index) in playlist.tracks" :key="index" @click="play(track.id)">
              <td>{{index+1}}</td>
              <td>
                <div class="img-wrap">
                  <img :src="track.al.picUrl" alt="" />
                  <span class="iconfont icon-play"></span>
                </div>
              </td>
              <td>
                <div class="song-wrap">
                  <div class="name-wrap">
                    <span>{{track.name}}</span>
                    <span class="iconfont icon-mv"></span>
                  </div>
                  <span>{{track.alia[0]}}</span>
                </div>
              </td>
              <td>{{track.ar[0].name}}</td>
              <td>{{track.al.name}}</td>
              <td>03:30</td>
            </tr>
          </tbody>
        </table>
      </el-tab-pane>
      <el-tab-pane label="评论(66)" name="2">
        <!-- 精彩评论 -->
        <div class="comment-wrap">
          <p class="title">精彩评论<span class="number">({{hotCount}})</span></p>
          <div class="comments-wrap">
            <div v-for="(hotComment, index) in hotComments" :key="index" class="item">
              <div class="icon-wrap">
                <img :src="hotComment.user.avatarUrl" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{hotComment.user.nickname}}:</span>
                  <span class="comment">{{hotComment.content}}</span>
                </div>
                <div class="re-content" v-if="hotComment.beReplied.length">
                  <span class="name">{{hotComment.beReplied[0].user.nickname}}:</span>
                  <span class="comment">{{hotComment.beReplied[0].content}}</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 最新评论 -->
        <div class="comment-wrap">
          <p class="title">最新评论<span class="number">({{Count}})</span></p>
          <div class="comments-wrap">
            <div v-for="(comment, index) in comments" :key="index" class="item">
              <div class="icon-wrap">
                <img :src="comment.user.avatarUrl" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{comment.user.nickname}}:</span>
                  <span class="comment">{{comment.content}}</span>
                </div>
                <div class="re-content" v-if="comment.beReplied.length">
                  <span class="name">{{comment.beReplied[0].user.nickname}}:</span>
                  <span class="comment">{{comment.beReplied[0].content}}</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页器 -->
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="5"
        >
        </el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'playlist',
  data() {
    return {
      activeIndex: '1',
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 歌单详情数据
      playlist:{},
      // 热门评论
      hotComments:[],
      // 最新评论
      comments:[],
      // 热门评论的个数
      hotCount:0,
      // 最新评论的个数
      Count:0

    };
  },
  created() {
    // 获取歌单详情
    axios({
      url:'https://autumnfish.cn/playlist/detail',
      method:'get',
      params:{
        id:this.$route.query.name
      }
    }).then(res=>{
      // console.log(res);
      this.playlist = res.data.playlist
    })
    // 获取精彩评论
     axios({
      url:' https://autumnfish.cn/comment/hot',
      method:'get',
      params:{
        id:this.$route.query.name,
        type:2
      }
    }).then(res=>{
      // console.log(res);
      this.hotComments = res.data.hotComments
      // 保存个数
      this.hotCount = res.data.total
    })
    // 获取最新评论
    axios({
      url:'https://autumnfish.cn/comment/playlist',
      method:'get',
      params:{
        id:this.$route.query.name,
        limit:10,
        offest:0
      }
    }).then(res=>{
      console.log(res);
      // 总个数
      this.total = res.data.total
      // 评论数据
      this.comments = res.data.comments
      // 最新评论个数
      this.Count = res.data.total
    })
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      // 保存页码
      this.page = val
      // 重新获取数据
    axios({
      url:'https://autumnfish.cn/comment/playlist',
      method:'get',
      params:{
        id:this.$route.query.name,
        limit:10,
        offset:(this.page-1)*10
      }
    }).then(res=>{
      // console.log(res);
      // 总个数
      this.total = res.data.total
      // 评论数据
      this.comments = res.data.comments
      // 最新评论个数
      this.Count = res.data.total
    })

    },
    // 播放歌单中的歌曲
    play(id){
       axios({
        url:'https://autumnfish.cn/song/url',
        method:'get',
        params:{
          id
        }
      }).then(res=>{
        console.log(res);
        let url = res.data.data[0].url
        // 设置给父组件的播放地址
        this.$parent.musicUrl = url
      })
    }
  }
};
</script>

<style >

</style>
